﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;
using Business;

namespace GestorEventos
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Evento business = new Evento();
            
            List<String> listaCategorias = business.getCategoriasEvento();


            for (int i = 0; i < listaCategorias.Count; i++) {
                DropDownListCategoria.Items.Add(listaCategorias[i]);
            }

            
        }

        public void getData(Object o, EventArgs e) {

            int value;
            
            String nome, descricao, link, categoria;
            double preco = -1;
            DateTime dataInicio, dataFim;
            nome = TextBoxNome.Text;
            descricao = TextBoxDescricao.Text;
            dataInicio = Convert.ToDateTime(TextBoxDataInicio.Text);
            dataFim = Convert.ToDateTime(TextBoxDataFim.Text);
            
            
            LabelDataFim.Text = dataFim.ToShortDateString();
            link = TextBoxLink.Text;
            if (TextBoxPreco.Text != null)
            {
                preco = Convert.ToDouble(TextBoxPreco.Text);
            }
            categoria = DropDownListCategoria.SelectedItem.Text;

            Evento novoEvento = new Evento(nome, dataInicio, dataFim, descricao, (float)preco, categoria, link);
            value = novoEvento.insertEvento();

            if (value > 0)
            {
                Response.Redirect("showEvento.aspx?eventID=" + novoEvento.getID() + "");

            }
            else {
                Response.Redirect("addEvento.aspx");
            }

            
            

            /*
            if (value!=-1) {
                LabelCategoria.Text = "Bota :D";
            }

            if (value==-1) {
                LabelCategoria.Text = "BOTA FAIL :(";
            }*/


        
        }
    }
}
